package com.tjp.subject.common.entity;

import com.tjp.subject.common.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @program: jz-club
 * @description:
 * @author: aaronTang
 * @create: 2024-02-22
 */
@Data
public class JZResult<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static JZResult ok() {
        JZResult jzResult = new JZResult();
        jzResult.setSuccess(true);
        jzResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        jzResult.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        return jzResult;
    }


    public static <T> JZResult ok(T data) {
        JZResult jzResult = new JZResult();
        jzResult.setSuccess(true);
        jzResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        jzResult.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        jzResult.setData(data);
        return jzResult;
    }

    public static JZResult fail() {
        JZResult jzResult = new JZResult();
        jzResult.setSuccess(false);
        jzResult.setCode(ResultCodeEnum.FAIL.getCode());
        jzResult.setMessage(ResultCodeEnum.FAIL.getDesc());
        return jzResult;
    }


    public static <T> JZResult fail(T data) {
        JZResult jzResult = new JZResult();
        jzResult.setSuccess(false);
        jzResult.setCode(ResultCodeEnum.FAIL.getCode());
        jzResult.setMessage(ResultCodeEnum.FAIL.getDesc());
        jzResult.setData(data);
        return jzResult;
    }

}
